/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

/**
 *
 * @author Didik
 */
public class Utils {

    String[] command;
    String feedbackcommand;

    public String[] getCommand() {
        return command;
    }

    public void setCommand(String command) {
        String delims = "[#/<> ]+";
        this.command = command.split(delims);
    }

    public String getFeedbackcommand() {
        return feedbackcommand;
    }

    public void setFeedbackcommand(String feedbackcommand) {
        this.feedbackcommand = feedbackcommand;
    }

    public void execute() {
        if (command.length > 1 && command.length < 5) {
            if (command.length == 2) {
                if (command[1].equalsIgnoreCase("info")) {
                    setFeedbackcommand("showing info...");
                } else if (command[1].equalsIgnoreCase("exit")) {
                    setFeedbackcommand("exit...");
                } else {
                    setFeedbackcommand("Wrong command!");
                }
            } else if (command.length == 3) {
                if (command[1].equalsIgnoreCase("create")) {
                    setFeedbackcommand("creating #" + command[2] + "...");
                } else if (command[1].equalsIgnoreCase("join")) {
                    setFeedbackcommand(command[1] + "ing #" + command[2] + "...");
                } else if (command[1].equalsIgnoreCase("chat")) {
                    setFeedbackcommand("creating " + command[1] + " room with " + command[2] + "...");
                } else if (command[1].equalsIgnoreCase("addfriend")) {
                    setFeedbackcommand("add " + command[2] + " as friend...");
                } else if (command[1].equalsIgnoreCase("info")) {
                    setFeedbackcommand("showing " + command[2] + "'s " + command[1] + "rmation");
                } else if (command[1].equalsIgnoreCase("kick")) {
                    setFeedbackcommand(command[1]+" "+command[2]+" from this room...");
                } else if (command[1].equalsIgnoreCase("ban")) {
                    setFeedbackcommand(command[1]+" "+command[2]+" from this room...");
                } else if (command[1].equalsIgnoreCase("unban")) {
                    setFeedbackcommand(command[1]+" "+command[2]+" from this room...");
                } else if (command[1].equalsIgnoreCase("persist")) {
                    setFeedbackcommand("set "+command[1]+" "+command[2]);
                } else if (command[1].equalsIgnoreCase("setowner")) {
                    setFeedbackcommand("change owner to "+command[2]);
                } else {
                    setFeedbackcommand("Wrong command!");
                }

            } else if (command[1].equalsIgnoreCase("create")) {
                //fungsi create room dg nama command[1]
                setFeedbackcommand("creating #" + command[2] + " in " + command[3] + "...");
            }
        } else {
            setFeedbackcommand("Wrong command!");
        }
    }

    public String[] parseCommand(String cmd) {
        String[] ret;
        String delims = "[#/<> ]+";
        ret = cmd.split(delims);
        return ret;
    }

    /*
    3kata
    /create roomname [kat/sub]

    2kata
    /create roomname
    /join roomname
    /chat username
    /addfriend username
    /info [roomname|username]
    /kick username
    /ban username
    /unban username
    /persist on|off
    /setowner username

    1kata
    /exit
    /info

     */
    public void run(String command) {
        String[] cmd = parseCommand(command);
        if (cmd.length > 0 && cmd.length < 4) {
            if (cmd[0].equalsIgnoreCase("create")) {
                //fungsi create room dg nama cmd[1]
            }

            if (cmd.length < 3) {
                if (cmd[0].equalsIgnoreCase("create")) {
                }
                if (cmd[0].equalsIgnoreCase("join")) {
                }
                if (cmd[0].equalsIgnoreCase("chat")) {
                }
                if (cmd[0].equalsIgnoreCase("addfriend")) {
                }
                if (cmd[0].equalsIgnoreCase("info")) {
                }
                if (cmd[0].equalsIgnoreCase("kick")) {
                }
                if (cmd[0].equalsIgnoreCase("ban")) {
                }
                if (cmd[0].equalsIgnoreCase("unban")) {
                }
                if (cmd[0].equalsIgnoreCase("persist")) {
                }
                if (cmd[0].equalsIgnoreCase("setowner")) {
                }

                if (cmd.length < 2) {
                    if (cmd[0].equalsIgnoreCase("info")) {
                    }
                    if (cmd[0].equalsIgnoreCase("exit")) {
                    }
                }
            }
        } else {
            System.out.println("Wrong command!");
        }

    }
}
